package org.android.kumoh_ing;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;


public class CalendarListView extends ListView {

	/**
	 * DataAdapter for this instance
	 */
	private FeedListAdapter adapter;
	private Context mcontext;

	/**
	 * Listener for data selection
	 */
	private OnDataSelectionListener selectionListener;
	private OnDataLongSelectionListener mLongClickListener;	
	
	public CalendarListView(Context context) { 
		super(context);
		mcontext = context;
		init();
	}
	
///TESTING!!!!

	public CalendarListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mcontext = context;
		init();
	}

	/**
	 * set initial properties
	 */ 
	private void init() { 
        setOnItemClickListener(new OnItemClickAdapter()); 
        setOnItemLongClickListener(new OnItemLongClickAdapter());
	}

	/**
	 * set DataAdapter
	 *
	 * @param adapter
	 */
	public void setAdapter(BaseAdapter adapter) {
		super.setAdapter(adapter);

	}

	/**
	 * get DataAdapter
	 *
	 * @return
	 */
	public BaseAdapter getAdapter() {
		return (BaseAdapter)super.getAdapter();
	}

	/**
	 * set OnDataSelectionListener
	 *
	 * @param listener
	 */
	public void setOnDataSelectionListener(OnDataSelectionListener listener) {
		
		this.selectionListener = listener;
	}
	public void setOnLongSelectionListener(OnDataLongSelectionListener listener){
		this.mLongClickListener = listener;
	}


	/**
	 * get OnDataSelectionListener
	 *
	 * @return
	 */
	public OnDataSelectionListener getOnDataSelectionListener() {
		return selectionListener;
	}

	class OnItemClickAdapter implements OnItemClickListener {

		public OnItemClickAdapter() {

		}
		
		public void onItemClick(AdapterView parent, View v, int position, long id) {
			if (selectionListener == null) {
				return;
			}
			

			// call the OnDataSelectionListener method
			selectionListener.onDataSelected(parent, v, position, id);

		}

	}
	class OnItemLongClickAdapter implements OnItemLongClickListener{
		public OnItemLongClickAdapter(){
			
		}

		@Override
		public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
			// TODO Auto-generated method stub
			if(mLongClickListener == null){
				return false;
			}
			mLongClickListener.onItemLongClick(arg0, arg1, arg2, arg3);
			return false;
		}
	
	}

}